package com.css.fxfzfxqh.modules.buildingResetUnitPrice.verify;

import cn.afterturn.easypoi.excel.entity.result.ExcelVerifyHandlerResult;
import cn.afterturn.easypoi.handler.inter.IExcelVerifyHandler;
import com.css.fxfzfxqh.base.dict.service.DictItemService;
import com.css.fxfzfxqh.base.dict.viewobjects.DictEntityVo;
import com.css.fxfzfxqh.modules.buildingResetUnitPrice.entity.BuildingResetUnitPriceEntity;
import com.css.fxfzfxqh.util.PlatformObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

@Component
public class BuildingVerifyHandler implements IExcelVerifyHandler<BuildingResetUnitPriceEntity> {

    @Autowired
    DictItemService dictItemService;

    @Override
    public ExcelVerifyHandlerResult verifyHandler(BuildingResetUnitPriceEntity buildingResetUnitPriceEntity) {
        ExcelVerifyHandlerResult result = new ExcelVerifyHandlerResult(true);
        StringBuilder message = new StringBuilder("");
        if (PlatformObjectUtils.isEmpty(buildingResetUnitPriceEntity.getProvince())) {
            result.setSuccess(false);
            message.append("省 不能为空、");
        }
        if (PlatformObjectUtils.isEmpty(buildingResetUnitPriceEntity.getCity())) {
            result.setSuccess(false);
            message.append("市 不能为空、");
        }
        if (PlatformObjectUtils.isEmpty(buildingResetUnitPriceEntity.getCounty())) {
            result.setSuccess(false);
            message.append("县 不能为空、");
        }
        if (PlatformObjectUtils.isEmpty(buildingResetUnitPriceEntity.getBrickConcrete())){
            result.setSuccess(false);
            message.append("砌体架构-砖混结构 不能为空、");
        }else{
            if(!pattern(buildingResetUnitPriceEntity.getBrickConcrete())){
                result.setSuccess(false);
                message.append("砌体架构-砖混结构 需为非负数且小数位不超过两位、");
            }
        }

        if (PlatformObjectUtils.isEmpty(buildingResetUnitPriceEntity.getStoneWood())){
            result.setSuccess(false);
            message.append("砌体架构-石木结构 不能为空、");
        }else{
            if(!pattern(buildingResetUnitPriceEntity.getStoneWood())){
                result.setSuccess(false);
                message.append("砌体架构-石木结构 需为非负数且小数位不超过两位、");
            }
        }

        if (PlatformObjectUtils.isEmpty(buildingResetUnitPriceEntity.getBrickWood())){
            result.setSuccess(false);
            message.append("砌体架构-砖木结构 不能为空、");
        }else{
            if(!pattern(buildingResetUnitPriceEntity.getBrickWood())){
                result.setSuccess(false);
                message.append("砌体架构-砖木结构 需为非负数且小数位不超过两位、");
            }
        }

        if (PlatformObjectUtils.isEmpty(buildingResetUnitPriceEntity.getReinforcedConcreteFrame())){
            result.setSuccess(false);
            message.append("钢筋混凝土结构-框架结构 不能为空、");
        }else{
            if(!pattern(buildingResetUnitPriceEntity.getReinforcedConcreteFrame())){
                result.setSuccess(false);
                message.append("钢筋混凝土结构-框架结构 需为非负数且小数位不超过两位、");
            }
        }

        if (PlatformObjectUtils.isEmpty(buildingResetUnitPriceEntity.getReinforcedConcreteFrameShearWall())){
            result.setSuccess(false);
            message.append("钢筋混凝土结构-框架-剪力墙结构 不能为空、");
        }else{
            if(!pattern(buildingResetUnitPriceEntity.getReinforcedConcreteFrameShearWall())){
                result.setSuccess(false);
                message.append("钢筋混凝土结构-框架-剪力墙结构 需为非负数且小数位不超过两位、");
            }
        }

        if (PlatformObjectUtils.isEmpty(buildingResetUnitPriceEntity.getReinforcedConcreteShearWall())){
            result.setSuccess(false);
            message.append("钢筋混凝土结构-剪力墙结构 不能为空、");
        }else{
            if(!pattern(buildingResetUnitPriceEntity.getReinforcedConcreteShearWall())){
                result.setSuccess(false);
                message.append("钢筋混凝土结构-剪力墙结构 需为非负数且小数位不超过两位、");
            }
        }

        if (PlatformObjectUtils.isEmpty(buildingResetUnitPriceEntity.getSoilWood())){
            result.setSuccess(false);
            message.append("土木结构 不能为空、");
        }else{
            if(!pattern(buildingResetUnitPriceEntity.getSoilWood())){
                result.setSuccess(false);
                message.append("土木结构 需为非负数且小数位不超过两位、");
            }
        }

        if (PlatformObjectUtils.isEmpty(buildingResetUnitPriceEntity.getWood())){
            result.setSuccess(false);
            message.append("木结构 不能为空、");
        }else{
            if(!pattern(buildingResetUnitPriceEntity.getWood())){
                result.setSuccess(false);
                message.append("木结构 需为非负数且小数位不超过两位、");
            }
        }

        if (PlatformObjectUtils.isEmpty(buildingResetUnitPriceEntity.getSteel())){
            result.setSuccess(false);
            message.append("钢结构 不能为空、");
        }else{
            if(!pattern(buildingResetUnitPriceEntity.getSteel())){
                result.setSuccess(false);
                message.append("钢结构 需为非负数且小数位不超过两位、");
            }
        }

        if (PlatformObjectUtils.isEmpty(buildingResetUnitPriceEntity.getIndustrialBrickConcrete())){
            result.setSuccess(false);
            message.append("工业厂房-砖混结构厂房 不能为空、");
        }else{
            if(!pattern(buildingResetUnitPriceEntity.getIndustrialBrickConcrete())){
                result.setSuccess(false);
                message.append("工业厂房-砖混结构厂房 需为非负数且小数位不超过两位、");
            }
        }

        if (PlatformObjectUtils.isEmpty(buildingResetUnitPriceEntity.getIndustrialReinforcedConcrete())){
            result.setSuccess(false);
            message.append("工业厂房-钢筋混凝土结构厂房 不能为空、");
        }else{
            if(!pattern(buildingResetUnitPriceEntity.getIndustrialReinforcedConcrete())){
                result.setSuccess(false);
                message.append("工业厂房-钢筋混凝土结构厂房 需为非负数且小数位不超过两位、");
            }
        }

        if (PlatformObjectUtils.isEmpty(buildingResetUnitPriceEntity.getIndustrialSteel())){
            result.setSuccess(false);
            message.append("工业厂房-钢结构厂房 不能为空、");
        }else{
            if(!pattern(buildingResetUnitPriceEntity.getIndustrialSteel())){
                result.setSuccess(false);
                message.append("工业厂房-钢结构厂房 需为非负数且小数位不超过两位、");
            }
        }

        if (PlatformObjectUtils.isEmpty(buildingResetUnitPriceEntity.getComposite())){
            result.setSuccess(false);
            message.append("组合结构 不能为空、");
        }else{
            if(!pattern(buildingResetUnitPriceEntity.getComposite())){
                result.setSuccess(false);
                message.append("组合结构 需为非负数且小数位不超过两位、");
            }
        }

        if (PlatformObjectUtils.isEmpty(buildingResetUnitPriceEntity.getOther())){
            result.setSuccess(false);
            message.append("其他 不能为空、");
        }else{
            if(!pattern(buildingResetUnitPriceEntity.getOther())){
                result.setSuccess(false);
                message.append("其他 需为非负数且小数位不超过两位、");
            }
        }

        String mess = message.toString();
        if (!PlatformObjectUtils.isEmpty(mess)) {
            mess = mess.substring(0,mess.length()-1)+"。";
        }
        result.setMsg(mess);
        return result;
    }

    public static void main(String[] args) {
        boolean pattern = pattern("3");
        System.err.println(pattern);
    }
    //非负数  并且小数位不能超过两位
    private static boolean pattern(String str){
        String pattern = "^\\d+(\\.\\d{1,2})?$";
        return str.matches(pattern);
    }

}
